package HLLib.ui;

import HLCode.HLClass;
import HLCode.HLClassManager;
import HLCode.HLClassManager_H;
import HLCode.HLObject;
import HLLib.base.HLGraphics;
import HLLib.base.HLRectangle;
import HLLib.base.HLString;
import HLLib.io.HLFile;

public class HLUIControlText extends HLUIControl {
    public HLClass GetClass(HLClassManager classManager) {
        return classManager.GetLibClass(HLClassManager_H.CLASS_GROUP_TYPE_LIB_UI, HLClassManager_H.LIB_CLASS_UI_UIControlText);
    }

    public int GetInt(int index) {
        switch (index) {
        case 1: {
            return textPosStyle;
        }
        case 2: {
            return imageListUIFrameIndex;
        }
        }
        return super.GetInt(index);
    }

    public void SetInt(int index, int value) {
        switch (index) {
        case 1: {
            textPosStyle = (byte) value;
            return;
        }
        case 2: {
            imageListUIFrameIndex = (byte) value;
            return;
        }
        }
        super.SetInt(index, value);
    }

    public boolean GetBoolean(int index) {
        return super.GetBoolean(index);
    }

    public void SetBoolean(int index, boolean value) {
        super.SetBoolean(index, value);
    }

    public HLObject GetObject(int index) {
        return super.GetObject(index);
    }

    public void SetObject(int index, HLObject value) {
        super.SetObject(index, value);
    }

    HLString text;

    public byte textPosStyle;

    public byte imageListUIFrameIndex;

    public HLUIControlText() {
    }

    HLUIControlText(HLUIFrame ownerFrame) {
        super(ownerFrame);
    }

    void Load(HLFile file) {
        super.Load(file);
        text = file.ReadString();
        textPosStyle = file.ReadInt8();
        imageListUIFrameIndex = file.ReadInt8();
    }

    public void SetText(HLString text, char startChar) {
        char[] chars = new char[text.string.length()];
        for (int i = 0; i < text.Length(); i++) {
            chars[i] = (char) (text.CharAt(i) - startChar + 1);
        }
        this.text.string = String.valueOf(chars);
    }

    void Render(HLGraphics g, int rectX, int rectY, int rectWidth, int rectHeight, int color) {
        HLRectangle area = GetArea(rectX, rectY, rectWidth, rectHeight);
        g.DrawImageStringAdjustableEX(ownerFrame.owner.GetImageList(imageListUIFrameIndex), (char) 1, 1, text, area.x, area.y, area.width, area.height, textPosStyle, TRANS_NONE, 10000, 10000, color, 0, 0, 0);
    }

    void CopyFrom(HLUIControl uiControl) {
        super.CopyFrom(uiControl);

        HLUIControlText uiControlByType = (HLUIControlText) uiControl;

        text = new HLString(uiControlByType.text.string);
        textPosStyle = uiControlByType.textPosStyle;
        imageListUIFrameIndex = uiControlByType.imageListUIFrameIndex;
    }

    HLUIControl Clone(HLUIFrame ownerFrame) {
        HLUIControlText uiControl = new HLUIControlText();
        uiControl.ownerFrame = ownerFrame;
        uiControl.CopyFrom(this);
        return uiControl;
    }
}
